package com.iplay.实战java高并发程序设计.chapter5.c55;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

/**
 * @author dangwu
 * @since 2021/11/5 5:41 下午
 */
public class FutureMain {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<String> futureTask = new FutureTask<>(new RealData2("a"));
        ExecutorService executor = Executors.newFixedThreadPool(1);
        //执行FutureTask，相当于上例中的client.request("a")发送请求
        executor.submit(futureTask);
        System.out.println("请求完毕");
        try {
            //模拟业务
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("数据=" + futureTask.get());
    }
}
